package
{
	import Classes.pi_TransparentJPG;
	
	import SEApp.components.se_loadProgress;
	import SEApp.dialogs.se_alert;
	import SEApp.dialogs.se_userPhotosDialog;
	import SEApp.se_app;
	import SEApp.se_sapp;
	import SEApp.se_util;
	
	import UIFree.FXEvent;
	import UIFree.ObjectEvent;
	import UIFree.controls.uif_button;
	import UIFree.controls.uif_hint;
	import UIFree.uif_Timer;
	import UIFree.uif_bitmap;
	import UIFree.uif_ecomponent;
	import UIFree.uif_loader;
	
	import UIUtils.Exif.ExifHeader;
	import UIUtils.JPGEncoder;
	import UIUtils.uif_util;
	import UIUtils.uif_utilS;
	
	import api_servers.api_server;
	
	import classes.clt_events;
	import classes.clt_images;
	import classes.clt_loader;
	import classes.clt_locale;
	import classes.clt_utils;
	
	import components.clothingLayer.clt_clothingLayer;
	import components.clt_component;
	import components.clt_layer;
	import components.clt_propertyLayer;
	import components.clt_workspace;
	import components.dialogs.clt_inputDialog;
	import components.game.clt_gameParams;
	import components.hairLayer.clt_hairLayer;
	import components.photoLayer.clt_photoLayer;
	import components.plugins.mlp.clt_mlpImage;
	import components.resultLayer.clt_resultLayer;
	import components.tools.clt_toolsBlock;
	
	import data.cd_background;
	import data.cd_clothing;
	import data.cd_data;
	import data.cd_defaults;
	import data.cd_hairs;
	import data.cd_masks;
	import data.cd_stikers;
	import data.cd_utils;
	import data.cd_workspaces;
	import data.clt_data;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.LoaderInfo;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;
	import flash.system.Security;
	import flash.system.SecurityDomain;
	import flash.utils.ByteArray;
	
	public class clt_clothingBase extends se_sapp {
		public static const toGameSize: Point = new Point(600, 600);
		
		private var _workspace		: clt_workspace;
		private var _pLayer			: clt_photoLayer;
		private var _hLayer			: clt_hairLayer;
		private var _cLayer			: clt_clothingLayer;
		private var _tools			: clt_toolsBlock;
		private var _sitedata		: Object;
		private var _safePos		: Object;
		protected var _rLayer		: clt_resultLayer;
		protected var _pluginLoaded	: Object;
		
		public static const PLWIDTH			: int = 260;
		
		public function clt_clothingBase(appWidth:uint, appHeight:uint, layerCount:uint=6) {
			Security.allowDomain('*');
			Security.loadPolicyFile(clt_servers.TMPL_URL + 'crossdomain.xml');
			resetData();
			super(appWidth, appHeight, layerCount);
			new se_loadProgress(topLayer, clt_images.c_loader3);
			new uif_hint(topLayer, 0, 0, 150, 160, 'hint', true);
			_sitedata = initSiteData();
//			initialize();
		}
		
		protected function listenEvents(): void {
			stage.addEventListener(Event.RESIZE, doStageResize);
		}
		
		public function getCollageLink(collageData: Object): String {
			return '';
		}
		
		public function get flashVars(): Object {
 			return Object( LoaderInfo(stage.loaderInfo ).parameters );			
		}
		
		protected function initTopBanner(): void {
			
		}
		
		protected function get lentaHeight(): Number {
			return 170;	
		}
		
		public function processingParams(a_params: Object): void {
			if (a_params) {
				doProcessingParams(a_params);
			}
		}
		
		protected function doProcessingParams(a_params: Object): void {
			if (a_params.game_id) collageView(a_params.game_id);
			if (a_params.element) parseElementParam(a_params.element);
		}
		
		protected function parseElementParam(element: String): void {
			var ae: Array = element.split(',');
			for (var i: int=0; i<ae.length; i += 2) {
				addElementJPGTmpl(ae[i], clt_servers.FRAME_URL + 'jpg/' + ae[i + 1]);
			}
		}
		
		public function addElementJPGTmpl(elementName: String, JPGUrl: String, a_data: Object = null, afterProc: Function=null): void {
			pi_TransparentJPG.load(JPGUrl + clt_data.JPGEXT,
				JPGUrl + 'm' + clt_data.JPGEXT,
				app, function(_jpgBitmap: Bitmap, bmdMask: BitmapData): void {
					_jpgBitmap.smoothing = true;
					workspace.dispatchEvent(new ObjectEvent(clt_events.SETELEMENT, {
						name	: elementName,
						bmp		: _jpgBitmap,
						data	: a_data?a_data:{}
					}));
					bmdMask.dispose();
					if (afterProc != null) afterProc();
				});			
		}
		
		protected function collageView(game_id: uint): void {
			if (game_id) {
				internalServer.getGame(externalServer.viewer_id, game_id, function(a_data: Object): void {
					var gameInfo: Object = a_data.response[0];
					if (gameInfo && gameInfo.uid) {
						externalServer.getProfiles(gameInfo.uid, function(a_data: Object): void {
							gameInfo = uif_util.union(gameInfo, a_data[0]);
							function beginShowCollage(e: Event = null): void {
								workspace.removeEventListener(clt_events.INUSER, beginShowCollage);
								workspace.dispatchEvent(new ObjectEvent(clt_events.SHOWGAMEITEM, gameInfo));
							}
							if (user.myData) beginShowCollage();
							else workspace.addEventListener(clt_events.INUSER, beginShowCollage);
						});
					} else alert(locale.WARNING, sitedata.EMPTYGAME);
				})
			}
		}
		
		override protected function initialize(): void {
			super.initialize();
			createWorkspace();
			createComponents();
			queryUserData(doQueryUserDataComplete);
			userMyDataRefresh();
			listenEvents();
		}
		
		protected function doStageResize(e: Event): void {
			updateScaleFromStage();
		}
		
		protected function updateScaleFromStage(): void {
			scale = stage.stageWidth / width; 
		}
		
		public function get isBanUser(): Boolean {
			return	user.myData? 
				((user.myData.user.banType == clt_data.BANTEMPO) || (user.myData.user.banType == clt_data.BANFOREVER)):false;
		}
		
		protected function doQueryUserDataComplete(userData: Object): void {
			function age(): int {
				var r_age: int = userData.age;
				if (!r_age) {
					var a: Array = (user.birthday as String).split('.');
					var y: int = int(a[2]);
					r_age = (new Date()).fullYear - y;
				}
				return r_age;
			}
			
			if (userData) {
				user = uif_util.union(user, userData);
				user.age = age();
				
				if ((user.sex == 1) && (user.age <= 12)) user.sex = 3;
				user.templateSex = user.sex;
				
				if (_pLayer) setDefaultTemplate(user.templateSex);
				initTopBanner();
				workspaceEvents();
				_workspace.dispatchEvent(new Event(clt_events.USERUPDATE));
			}
		}
		
		protected function createWorkspace(): void {
			_workspace 	= new clt_workspace(this);
			_workspace.info = cd_workspaces.list[0];
		}
		
		protected function createComponents(): void {
			registerStartComponent(this);
			var rect: Rectangle = getInner();
			
			_hLayer 	= new clt_hairLayer(layers[0], lentaHeight, clt_layer.ALIGNTOP, 'block');
			_rLayer 	= new clt_resultLayer(layers[0], rect.width - PLWIDTH, clt_layer.ALIGNTOP, 'editor');
			_cLayer		= new clt_clothingLayer(layers[0], lentaHeight, clt_layer.ALIGNTOP, 'block');
			
			rect = _rLayer.getOuter(); 
			_pLayer		= new clt_photoLayer(layers[0], rect.x + rect.width - PLWIDTH, rect.y, PLWIDTH, rect.height, 'block');
			_tools		= new clt_toolsBlock(layers[0], rect.x, rect.y + rect.height * 0.5, _rLayer.editor.width, rect.height * 0.5);
			
			_safePos = new Object();
			_safePos.hairs 	= _hLayer.position.clone();
			_safePos.result = _rLayer.position.clone();
			if (user.hasOwnProperty('sex')) setDefaultTemplate(user.sex);
			
			(this.classes as Object).locale.BANASK += externalServer.viewer_id;
			(this.classes as Object).locale.BANCOMMENTS += (this.classes as Object).locale.BANASK;
			(this.classes as Object).locale.NOCREATECOLLAGE += (this.classes as Object).locale.BANASK;
			
			new clt_propertyLayer(layers[1], rect.x, rect.y, rect.width, rect.height);
		}
		
		public function calcHeight(stageWidth: Number): Number {
			var cwidth: Number = stageWidth - PLWIDTH;
			if (cwidth > clt_resultLayer.MAXRESULTSIZE) cwidth = clt_resultLayer.MAXRESULTSIZE;
			return lentaHeight + cwidth + lentaHeight + addedHeight();
		}
		
		protected function addedHeight(): Number {
			return 0;
		}
		
		public function get resultLayer(): clt_resultLayer {
			return _rLayer;
		}
		
		protected function userMyDataRefresh(): void {
			internalServer.inUser(flashVars.testUser?flashVars.testUser:externalServer.viewer_id, doMyDataComplete);
		}
		
		protected function setVipStatus(a_vip: Boolean): void {
			user.vipStatus 	= a_vip;
			user.noLinkText = a_vip;
			user.voteMega 	= a_vip;
			if (workspace) workspace.dispatchEvent(new Event(clt_events.DISPLAYREFRESH));
		}
		
		protected function doMyDataComplete(a_data: Object): void {
			if (a_data.response[0].user) {
				user.myData = a_data.response[0];
				if (user.myData.pays && user.myData.pays.length) {
					user.myData.pays.forEach(function(item: Object, index: int, arr: Array): void {
						if (item.service_id == clt_data.SVID_VOTEMEGA) user.voteMega = true;
						else if (item.service_id == clt_data.SVID_NOLINKTEXT) user.noLinkText = true; 
						else if (item.service_id == clt_data.SVID_VIPSTATUS) setVipStatus(true)
					})
				}
				
				if (user.myData.message)
					alert(locale.MESSAGE, user.myData.message);
				if (user.myData.plugins)
					loadPlugins(user.myData.plugins);
				workspace.dispatchEvent(new ObjectEvent(clt_events.INUSER, a_data.response[0].user));
			}
		}
		
		protected function loadPlugins(plugins: Object): void {
			_pluginLoaded = new Object();
			for (var i: String in plugins) {
				var a: Array = plugins[i].split(',');
				if (a[1]) {
					uif_Timer.one(a[1] * 1000, function(): void {
						loadPlugin(i, a[0]);
					});
				} else loadPlugin(i, a[0]);
			}
		}
		
		public function loadPlugin(name: String, pluginURL: String, doComplete: Function=null): Boolean {
			if (!_pluginLoaded[name]) {
				_pluginLoaded[name] = new uif_loader(this, clt_servers.MAIN_URL + clt_servers.PLUGINS_URL + pluginURL + '?ver=' + flashVars.ver, function(e: Event): void {
					e.target.content.init(This);
					if (doComplete != null) doComplete(e);
				}, 0, 0, new LoaderContext(true, ApplicationDomain.currentDomain, SecurityDomain.currentDomain));
				return true;
			} else return false;
		}		
		
		public function get locale(): Object {
			return app.classes.locale;
		}
		
		protected function doCollageToGame(baimage: ByteArray, result: Object, isMyAlbum: Boolean = false): void { // После отправки коллажа на конкурс
/*			
			var descr: String = Utils.sprintf(sitedata.INPUTNAMEGAME, result.id);
			clt_inputDialog.run(locale.WARNING, descr, function(text: String): void {
				internalServer.renameGame(result.id, text, 0, function(data: Object): void {
					user.myData.isMyGame.count++;
					workspace.dispatchEvent(new Event(clt_events.UPDATEGAME));
				})
			});
*/			
			if (!isMyAlbum) workspace.dispatchEvent(new Event(clt_events.UPDATEGAME));
		}
		
		public function toMyAlbumBmp(): void {
			toGameSend(true);
		}
		
/*	
		protected function noSendToMyAlbum(): void {
			alert(clt_locale.WARNING, clt_locale.TOMYALBUMVIPSTATUS, function(): void {
				
			}, true);
		}
*/		
		
		public function toGameMLP(isMyAlbum: Boolean, a_image: clt_mlpImage): void {
			function toGameMLPA(): void {
				var gp: clt_gameParams = new clt_gameParams(dialogLayer, function(): void {
					var bmd: BitmapData = se_util.bmpCopy(a_image, 60 / a_image.width).bitmapData;
					var preview: ByteArray = encodeFromJPG(bmd);
					var bytes: ByteArray = new ByteArray();
					bytes.writeInt(preview.length);
					bytes.writeBytes(preview);
					bytes.writeBytes(a_image.bytes);
					bmd.dispose();
					
					internalServer.imageFromGame(bytes, 
						gp.nameCollage, gp.stiker, function(a_data: Object): void {
							if (!a_data.errors && a_data.response && !isMyAlbum) 
								workspace.dispatchEvent(new Event(clt_events.UPDATEGAME));
							
							bytes.clear();
						}, true, isMyAlbum);
				}); 
				gp.show();
			}
			if (isMyAlbum) checkVipStatus(toGameMLPA);
			else toGameMLPA();
		}
		
		protected function toGameSendJPGData(baimage: ByteArray, gp: clt_gameParams, isMyAlbum: Boolean = false): void {
			internalServer.imageFromGame(baimage, gp.nameCollage, gp.stiker, function(a_data: Object): void {
				if (!a_data.errors && a_data.response) doCollageToGame(baimage, a_data.response[0], isMyAlbum)
			}, false, isMyAlbum);
		}
		
		public function toGameSend(isMyAlbum: Boolean = false, a_bmd: BitmapData=null): void {
			function toGameSendA(): void {
				var gp: clt_gameParams = new clt_gameParams(dialogLayer, function(): void {
					
					function toGameSendA(bmd: BitmapData): void {
						var baimage: ByteArray = encodeFromJPG(bmd);
						toGameSendJPGData(baimage, gp, isMyAlbum);
						bmd.dispose();
					}
					if (!a_bmd) getResult(toGameSize.x, toGameSize.y, toGameSendA, {
						noLinkText: true
					}) else toGameSendA(a_bmd);
				}); 
				gp.show();
			}
			
			if (isMyAlbum) checkVipStatus(toGameSendA);
			else toGameSendA();
		}

		protected function doAfterInviteToGame(e: ObjectEvent): void {
			if (e.object && e.object.length) toGameSend();
			removeEventListener(clt_events.INVITE, doAfterInviteToGame);
		}
		
		protected function doToGameComplete(): void {
			addEventListener(clt_events.INVITE, doAfterInviteToGame);
			dispatchEvent(new Event(clt_events.INVITEDIALOGSHOW));
		}
		
		protected function checkGameCollage(): Boolean {
			if (_pLayer.isDefaultPhoto && !externalServer.isAdmin()) {
				alert(locale.WARNING, locale.NOUSERDEFAULTPHOTO);
				return false;
			} else {
				if (isBanUser) {
					alert(locale.WARNING, locale.NOCREATECOLLAGE);
					return false;
				}
				return true;
			}
		}
		
		protected function doToGame(): void {
			if (checkGameCollage()) {
				if (user.vipStatus) toGameSend();
				else {
					var event: ObjectEvent = new ObjectEvent(clt_events.CHECKISGAME, {
						result: false
					})
					workspace.dispatchEvent(event);
					if (!event.object.result) // Если нет коллажа с участием текущего пользователя 
						toNewGame();
					else repeatGame();
				}
			}
		}
		
		protected function toNewGame(): void {
			alert(locale.WARNING, locale.INVITEFRIENDFROMGAME, doToGameComplete, true);
		}
		
		protected function repeatGame(): void {
			alert(locale.WARNING, locale.INVITEFRIENDFROMGAME, doToGameComplete, true);
		}

		protected function uploadResult(size: Point, doUpload: Function, path: String=''): void {
			getResult(size.x, size.y, function(bmd: BitmapData): void {
				internalServer.collectorImage(path, encodeFromJPG(bmd), function(a_data: Object): void {
					if (!a_data.errors && a_data.response) doUpload(a_data.response[0]);
				});
				bmd.dispose();			
			});
		}

		protected function setDefaultTemplate(sexIndex: int, updateAll: Boolean = false): void {
			var def: Object = cd_defaults.startData[sexIndex];
			if (updateAll) { 
/*				workspace.dispatchEvent(new ObjectEvent(clt_events.SELECTCUTOUT, 
					cd_utils.fromID(cd_masks.list, cd_defaults.masks[sexIndex].id)
				));*/
				workspace.dispatchEvent(new ObjectEvent(clt_events.SELECTCLOTH,
					cd_utils.fromID(cd_clothing.list, cd_defaults.cloth[sexIndex].id)
				));
				workspace.dispatchEvent(new ObjectEvent(clt_events.SELECTHAIR,
					cd_utils.fromID(cd_hairs.list, cd_defaults.hairs[sexIndex].id)
				));
			}
			workspace.dispatchEvent(new ObjectEvent(clt_events.SETHEAD, def));
			workspace.dispatchEvent(new Event(clt_events.DEAFULTTMPL));
		}
		
		public function get photoSelectMenu(): Object {
			return {
				list: [
					{caption: ' Из альбома ', method: 'doPhotoSelect'},
					{caption: ' С компьютера ', method: 'doPhotoLoad'},
					{caption: ' С веб-камеры ', method: 'doWebCamera'}
				],
				def: 'doPhotoSelect'
			}
		}
		
		protected function workspaceEvents(): void {
			function doRestore(): void {
				_hLayer.fx('x', _hLayer.x, _safePos.hairs.x).start();
				_rLayer.fx('y', _rLayer.y, _safePos.result.y).start();
				_hLayer.removeEventListener(MouseEvent.CLICK, doHClick);
			}
			
			function doHClick(e: Event): void {
				_tools.close();
				doRestore();
			}
			
			_workspace.addEventListener(clt_events.SHOWTOOLS, function(e: Event): void {
				_hLayer.fx('x', _hLayer.x, _pLayer.x).start(function(e:FXEvent): void {
					_hLayer.addEvent(MouseEvent.CLICK, doHClick);
				});
				_rLayer.fx('y', _rLayer.y, 0).start();
			});
			_workspace.addEventListener(clt_events.HIDETOOLS, function(e: Event): void {
				doRestore();
			});
			
			_workspace.addEventListener(clt_events.UPDATEWORKSPACE, doUpdateWorkspace);
			_workspace.addEventListener(clt_events.LOADPHOTOCOMPLETE, doStartLoadComplete);
			_workspace.addEventListener(clt_events.NOLINKTEXTRELEASE, doNoLinkRelease);
			_workspace.addEventListener(clt_events.STIKERCLICK, doStikerClick);
			
			function doStartLoadComplete(e: Event): void {
				_workspace.removeEventListener(clt_events.LOADPHOTOCOMPLETE, doStartLoadComplete);
				startComplete(This);
			}
			
			_workspace.addEventListener(clt_events.SHOWUSERPHOTOS, doShowUserPhotos);
			_workspace.addEventListener(clt_events.SELECTTEMPLATE, function(e: ObjectEvent): void {
				setDefaultTemplate(e.object as int, true);
			});
			
			addEventListener(se_alert.ALERT, doAlert);
		}
		
		protected function doAlert(e: ObjectEvent): void {
			alert(This.classes['locale'].WARNING, e.object as String);
		}
		
		protected function doShowUserPhotos(e: ObjectEvent): void {
			externalServer.getAlbums(e.object.uid, function(albums: Object): void {
				if (albums as Array) {
					var r_albums: Array = albumsPrepare(e.object.uid, albums as Array);
					if (r_albums && r_albums.length > 0) {
						var dlg: se_userPhotosDialog = new se_userPhotosDialog(topLayer, 500, 300);
						dlg.title.text = Utils.sprintf(locale.PHOTOSTITLE, se_util.userName(e.object));
						dlg.showPhotos(e.object.uid, r_albums);
						dlg.albums.addEvent(Event.SELECT, function(e: ObjectEvent): void {
							var pdata: Object = e.object.data;
							workspace.loadPhoto(pdata.pic_big?pdata.pic_big:
														pdata.src_big?pdata.src_big:
															pdata.src);
						});
					} else doResponseAlbumsError();
				} else doResponseAlbumsError();
			}, doResponseAlbumsError);
		}
		
		protected function doResponseAlbumsError(e: Event=null): void {
			alert(locale.WARNING, sitedata.NOUSERALBUMACCESS, function(): void {
				showInviteDialog();
			}, true);
		}
		
		public function showInviteDialog(a_params: Object=null): void {
		}
		
		public function get sitedata(): Object {
			return _sitedata;
		}
		
		protected function initSiteData(): Object {
			return {};
		}
		
		override protected function initLayers(layerCount: uint=6): void {
			var rect: Rectangle = runArea;
			_layers = new Array();
			for (var i: int =0; i<layerCount; i++) {
				_layers[i] = new clt_component(this, rect.x, rect.y, rect.width, rect.height);
			}
		}
		
		public function get runArea(): Rectangle {
			return getRunArea();
		}
		
		protected function getRunArea(): Rectangle {
			return getInner(0, 76);
		}
		
		override public function get dialogLayer(): uif_ecomponent {
			return layers[layers.length - 2];
		}
		
		override public function get popupMenuLayer(): uif_ecomponent {
			return layers[layers.length - 1];
		}
		
		protected function queryUserData(postFunc: Function): void {
		}
		
		public function encodeFromJPG(bmd: BitmapData): ByteArray {
			var je: JPGEncoder = new JPGEncoder(80);
//			var exif: ExifInfo = new ExifInfo(je.encode(bmd));
			
			return je.encode(bmd, new ExifHeader({
				SOFTWARE	: 'http://oformi-foto.ru',
				AUTOR		: uif_utilS.translit(se_util.userName(user)),
				SUBJECT		: uif_utilS.translit(locale.APPNAME),
				COMMENT		: 'API: ' + externalServer.api_url + ', UID: ' + user.uid
			}));
		}
		
		public function loadImage(event: String, filters: Array): void {
			var _fref: FileReference = new FileReference();
			
			function doSelectHandler(e: Event): void {
				_fref.load();
			}
			
			function doCompleteHandler(e: Event): void {
				workspace.loadImageBytes(_fref.data, event);
			}
			
			_fref.addEventListener(Event.COMPLETE, doCompleteHandler);
			_fref.addEventListener(Event.SELECT, doSelectHandler);
			
			_fref.browse(filters);
		}
		
		public function saveToFile(FileData: ByteArray, fileName: String=''): void {
			
			var alert: se_alert = new se_alert(topLayer, cd_data.SAVEDESCR, null, true);
			alert.title.text = cd_data.WARNING;
			alert.okButton.addEvent(MouseEvent.CLICK, function(e: Event): void {				
				var fr: FileReference;
				fr = new FileReference();
/*				if (incSaved) {
					function l_doComplete(e: Event): void {
						fr.removeEventListener(Event.COMPLETE, l_doComplete);
						if (incSaved) app.saveNotify();
					}
					fr.addEventListener(Event.COMPLETE, l_doComplete);
				}*/
				fr.save(FileData, fileName?fileName:genFileNameCard(clt_data.JPGEXT));
			});
			alert.show();
		}
		
		public function saveToAlbum(JPGData: ByteArray=null): void {
			
		}
		
		
		public function genFileNameCard(ext: String=''): String {
			return MD5.encrypt((Math.random() * 1000).toString()) + ext;
		}
		
		public function getResult(width: Number, height: Number, resultFunc: Function, a_options: Object=null): void {
			var response: Object = {
				size			: new Point(width, height),
				result			: null,
				options 		: a_options,
				responseFunc	: resultFunc
			};
			workspace.dispatchEvent(new ObjectEvent(clt_events.GETRESULTBMP, response));
			if (response.result && response.responseFunc) response.responseFunc(response.result);
		}
		
		public function get saveMenuList(): Array {
			return [];
		}
		
		protected function doStikerClick(e: Event): void {
			
		}
		
		protected function doUpdateWorkspace(e: Event): void {
		}
		
		protected function doNoLinkRelease(e: Event): void {
			
		}
		
		public function get workspace(): clt_workspace {
			return _workspace;
		}
		
		public static function button(parent: uif_ecomponent, x: Number, y: Number, 
									width: Number, height: Number, caption: String,
									onClick: Function, 
									classStyle: String='buttonB'): uif_button {
			var r_button: uif_button = new uif_button(parent, x, y, width, height, classStyle);
			r_button.text = caption;
			r_button.addEvent(MouseEvent.CLICK, onClick);
			return r_button; 
		}
		
		protected function resetData(): void {
			cd_utils.resetData(cd_hairs.list);
			cd_utils.resetData(cd_masks.list);
			cd_utils.resetData(cd_clothing.list);
			cd_utils.resetData(cd_background.list);
			cd_utils.resetData(cd_stikers.list);
		}
		
		override public function get classes(): Object {
			var result: Object 	= super.classes;
			result.loader 		= clt_loader;
			result.bitmap 		= uif_bitmap;
			result.bitmapData 	= BitmapData;
			result.locale		= clt_locale;
			result.data			= clt_data;
			result.component	= clt_component;
			return result;
		}
		
		override protected function createExternalServer(): api_server {
			return null;
		}
		
		public function filterAlbums(a_albums: Array): Array {
			return a_albums;
		}
		
		public function publicGameCollage(collageData: Object, a_title: String, a_description: String): void {
			
		}
		
		public function getGameList(params: String, _handle: Function): void {
			internalServer.getGameList(params, function(a_data: Object): void {
				getUsersDataFromList(a_data.list, _handle);
			})
		}
		
		public function getUsersDataFromList(a_list: Object, _handle: Function): void {
			var list: Array = a_list as Array;
			if (list && (list.length > 0)) {
				externalServer.getProfiles(se_util.getUids(list), function(a_users: Array): void {
					_handle(clt_utils.usersUnion(a_users, list));
				});
			} else _handle(list);
		}
		
		public function get tools(): clt_toolsBlock {
			return _tools;
		}
		
		public function checkVipStatus(_isVIPStatusFunc: Function): void {
			_isVIPStatusFunc();
		}
	}
}